package com.glorysoft.lipuxinpda.base

import android.Manifest
import android.app.Application
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.provider.Settings
import android.telephony.TelephonyManager
import android.widget.Toast
import androidx.core.app.ActivityCompat
import androidx.core.app.ActivityCompat.requestPermissions
import com.glorysoft.lipuxinpda.activity.LoginActivity
import com.pda.platform.ui.ui_pdaplatform.base.FreeUI_InitUtils
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_SharePreferencesUtils
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_StaticMembers

/**
 * FileName: App
 * Author: XJH
 * Date: 2021/4/8 15:58
 * Description:
 * History:
 */
class App : Application() {

    override fun onCreate() {
        super.onCreate()
        instance = this
        app = applicationContext

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED) {
                val telephonyManager = this.getSystemService(TELEPHONY_SERVICE) as TelephonyManager
                IMEI_ID = telephonyManager.deviceId
                if (IMEI_ID == null) {
                    IMEI_ID = Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
                }
            } else {
                //

            }
        } else {
            val telephonyManager = this.getSystemService(TELEPHONY_SERVICE) as TelephonyManager
            IMEI_ID = telephonyManager.deviceId
            if (IMEI_ID == null) {
                IMEI_ID = Settings.Secure.getString(applicationContext.contentResolver, Settings.Secure.ANDROID_ID)
            }
        }
        FreeApi_StaticMembers.CURRENT_THEME = FreeApi_StaticMembers.THEME_GLORY
        FreeUI_InitUtils.init(applicationContext, this, false, 60 * 1000L, 0)
        //Toast显示时长
        FreeApi_StaticMembers.TOASTSHOWTIME = Toast.LENGTH_LONG
    }

    companion object {
        var app: Context? = null
        var IMEI_ID: String? = null
        var instance: App? = null
        var workid: String? = null
    }

}